package reflect;

import jdk.nashorn.internal.ir.LiteralNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /* 可以获取的类名
        java.util.ArrayList
        java.util.HashMap
        java.util.Date
         */
        //1.获取要实例化的类的类对象
        //Class cls = ArrayList.class;
        //Class cls = HashMap.class;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名");
        String className = scanner.nextLine();
        Class cls = Class.forName(className);

        // 2.类对象提供了方法newInstance（）可以进行实例化
        Object obj = cls.newInstance();
        System.out.println(obj);
    }
}
